package com.hospital.doctor.controller;

import com.hospital.doctor.pojo.Operation;
import com.hospital.doctor.service.OperationService;
import com.hospital.doctor.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/operation")
@CrossOrigin
public class OperationController {

    @Autowired
    private OperationService operationService;

    /**
     * 根据患者id查询，
     * @param pId
     * @return
     */
    @RequestMapping("/selectBypId/{pId}")
    public Map<String,Object> selectBypId(@PathVariable("pId") int pId){
        Map<String,Object> map = new HashMap<>();
        map.put("msg",operationService.selectBypId(pId));
        return map;
    }

    @RequestMapping("/selectByoId/{oId}")
    public Map<String,Object> selectByoId(@PathVariable("oId") int oId){
        Map<String,Object> map = new HashMap<>();
        map.put("msg",operationService.selectByoId(oId));
        return map;
    }

    @RequestMapping("/insert")
    public Map<String,Object> selectBypId(@RequestBody Operation operation, HttpServletRequest request){
        operation.setdId(Integer.valueOf(JWTUtils.verify(request.getHeader("token")).getClaim("id").asString()));
        Map<String,Object> map = new HashMap<>();
        map.put("msg",operationService.insert(operation));
        return map;
    }



}
